home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_09
/
9n09076a
< prev
next >
Wrap
Text File
|
1991-07-08
|
12KB
|
352 lines
/******************************************************
* Listing 3 hostcom.c
*
* HOSTCOM PC - Host Communication Program
*
* written by Douglas Connolly
* 419 Hart Senate Office Building
* Washington, D.C. 20510
*
*****************************************************/
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include "hc.h"
/* screen attributes */
int norm_attr = ((BLACK<<4)+LIGHTGRAY); /* text */
int stat_attr = ((BLUE<<4)+WHITE); /* status line */
/* attributes for activity field */
int wait_attr = ((RED<<4) + WHITE); /* waiting */
int time_attr = ((GREEN<<4)+ WHITE); /* TIME */
int send_attr = ((CYAN<<4) + WHITE); /* sending */
int oia_attr = ((GREEN<<4)+ WHITE); /* OIA */
static char far *vid_mem; /* video memory pointer */
/* hllapi_level indicates the emulation software used:
* 0 = PC/3270 Ver. 1.0 PSID = A
* 1 = IBM Entry Level PSID = E
* 2 = Attachmate Extra PSID = B
* 3 = RabbitGATE PSID = 1
* 4 = simulated connection
* 5 = simulated connection with test data
*/
int hllapi_level;
/* clear_flag prevents 2 consecutive clear commands
* being sent to host (prevent Attachmate problems)
*/
int clear_flag = 0;
void main (int argc, char **argv)
{
int x, y, chr, err;
char api_ps[1921]; /* pres. space + 1 */
int k; /* char read from kbd */
char c[2] = " "; /* intput string */
int n = 0; /* cursor position */
/* power on/off string for RabbitGATE */
char rabbit_power[4] = {'@', 'A', 0x80, '\0'};
/* select emulation software */
if (argc < 2 ||
(hllapi_level = atoi(argv[1])) > 5) {
fprintf(stderr, HOSTCOM_MSG);
return;
}
if (hllapi_level == 4)
memset(api_ps, ' ', 1920);
/* copy test data to pres space */
else if (hllapi_level == 5)
for (x=0; x<24*80; x+=80) {
chr = 0x28;
for (y=0; y<80; y++)
api_ps[x+y] = chr++;
}
/* initialize video pointer */
if (set_vid() != 0) {
fprintf(stderr, VID_ERROR);
return;
}
/* connect presentation space */
if ((err = connect_ps_space()) != 0) {
fprintf(stderr, CONNECT_ERROR);
return;
}
clrscr();
write_string(1, 25, STAT_LINE, stat_attr);
/* RabbitGATE: Power on session */
if (hllapi_level == 3) {
write_string(1, 1," Powering on session"
" One moment ...", stat_attr);
send_key(rabbit_power);
delay(500);
if (!check_power()) {
puts("HOSTOCM: power on failed\n");
exit(1);
}
}
status_msg("Ready", stat_attr);
while (1) {
/* Wait for a key. While no key is
* waiting, continuously update PS.
*/
while (!kbhit()) {
if ((err=update_ps(api_ps))!=0) {
if (process_error(err) != 0) {
reset_connection();
return;
}
}
display_cursor();
}
k = get_key();
switch (k) {
case K_F3: /* clear */
/* Send clear key only if
* clear_flag is set.
*/
if (clear_flag) {
clear_flag = 0;
err = input_to_host("@C");
n = 0;
delay(500);
}
break;
case K_F4: /* reset */
err = input_to_host("@R");
n = 0;
break;
case K_F7: /* OIA */
if ((err = dspy_oia()) == 0) {
write_string(1,1,
OIA_MSG, stat_attr);
while (!receive_esc());
}
break;
case K_CF10: /* unconditional exit */
reset_connection();
clrscr();
return;
case K_F10: /* exit program */
if (check_signon()) {
/* warn if in application */
write_string(1, 1,
SIGNOFF_MSG, stat_attr);
while(!receive_esc());
}
else {
if (hllapi_level == 3)
/* power off */
send_key(rabbit_power);
if ((err =
reset_connection())
== 0) {
clrscr();
return;
}
}
break;
case K_HOME: /* home */
err = keys_to_host("@0");
n = 0;
break;
case K_CTRLR: /* return (newline) */
err = keys_to_host("@N");
n = 0;
break;
case K_ENTER: /* enter key */
/* set clear key flag */
clear_flag = 1;
err = input_to_host("@E");
n = 0;
break;
case K_LEFT: /* cursor left */
if (n>0) {
if ((err=keys_to_host("@L"))==0) {
n--;
err = display_cursor();
}
}
break;
case K_RIGHT: /* cursor right */
if ((err=keys_to_host("@Z"))==0) {
n++;
err = display_cursor();
}
break;
case K_TAB: /* tab */
err = keys_to_host("@T");
n = 0;
break;
case K_INS: /* insert */
err = keys_to_host("@I");
break;
case K_BACKTAB: /* backtab */
err = keys_to_host("@B");
n = 0;
break;
case K_DEL: /* delete right */
err = keys_to_host("@D");
break;
case K_BACKSPACE: /* backspace */
if (n>0) {
n--;
err = keys_to_host("@L");
if (err == 0)
err=keys_to_host("@D");
break;
}
else { /* at start of line */
putchar('\a');
continue;
}
default:
if (isascii(k)) {
putchar(k);
*c = (char) k;
err = keys_to_host(c);
n++;
}